<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>每日吸猫 | 登录</title>
    <style>
        /* 全局样式 */
        * {
            box-sizing: border-box;
            margin: 0;
            padding: 0;
        }
        
        body {
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            text-align: center;
            padding: 20px;
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            height: 100vh;
            margin: 0;
            background: linear-gradient(135deg, #ffecd2 0%, #fcb69f 100%);
            background-attachment: fixed;
            position: relative;
            overflow: hidden;
        }
        
        /* 背景装饰 */
        body::before {
            content: '';
            position: absolute;
            top: -150px;
            right: -150px;
            width: 400px;
            height: 400px;
            background: radial-gradient(circle, rgba(255,105,180,0.2) 0%, rgba(255,105,180,0) 70%);
            border-radius: 50%;
        }
        
        body::after {
            content: '';
            position: absolute;
            bottom: -150px;
            left: -150px;
            width: 400px;
            height: 400px;
            background: radial-gradient(circle, rgba(147,112,219,0.2) 0%, rgba(147,112,219,0) 70%);
            border-radius: 50%;
        }
        
        /* 登录表单容器 */
        .login-form {
            max-width: 400px;
            padding: 40px;
            border-radius: 20px;
            background: rgba(255, 255, 255, 0.95);
            box-shadow: 0 15px 35px rgba(0,0,0,0.2);
            position: relative;
            z-index: 1;
            border: 2px solid rgba(255, 105, 180, 0.3);
            backdrop-filter: blur(10px);
            transition: transform 0.3s ease, box-shadow 0.3s ease;
        }
        
        .login-form:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.25);
        }
        
        /* 输入框样式 */
        .login-form input {
            width: 100%;
            padding: 15px;
            margin: 15px 0;
            border: 2px solid rgba(147, 112, 219, 0.3);
            border-radius: 30px;
            font-size: 16px;
            transition: all 0.3s ease;
            background: rgba(255, 255, 255, 0.8);
        }
        
        .login-form input:focus {
            outline: none;
            border-color: #ff69b4;
            background: white;
            box-shadow: 0 0 15px rgba(255, 105, 180, 0.3);
            transform: translateY(-2px);
        }
        
        /* 按钮样式 */
        button {
            padding: 15px 30px;
            font-size: 18px;
            font-weight: bold;
            background-color: #ff69b4;
            color: white;
            border: none;
            border-radius: 30px;
            cursor: pointer;
            margin: 20px 0 15px;
            width: 100%;
            transition: all 0.3s ease;
            position: relative;
            overflow: hidden;
            text-transform: uppercase;
            letter-spacing: 0.5px;
        }
        
        button::before {
            content: '';
            position: absolute;
            top: 50%;
            left: 50%;
            width: 0;
            height: 0;
            background: rgba(255, 255, 255, 0.3);
            border-radius: 50%;
            transform: translate(-50%, -50%);
            transition: width 0.6s, height 0.6s;
        }
        
        button:hover::before {
            width: 300px;
            height: 300px;
        }
        
        button:hover {
            background-color: #ff1493;
            transform: translateY(-2px);
            box-shadow: 0 8px 20px rgba(255, 105, 180, 0.4);
        }
        
        button:active {
            transform: translateY(0);
        }
        
        /* 登录提示 */
        .login-note {
            font-size: 14px;
            color: #666;
            margin-top: 20px;
            font-style: italic;
        }
        
        /* 标题样式 */
        h1 {
            color: #333;
            margin-bottom: 30px;
            font-size: 2.5rem;
            font-weight: bold;
            text-shadow: 2px 2px 4px rgba(0,0,0,0.1);
            position: relative;
            z-index: 1;
            animation: float 3s ease-in-out infinite;
        }
        
        @keyframes float {
            0% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
            100% { transform: translateY(0px); }
        }
        
        h3 {
            color: #555;
            margin-bottom: 25px;
            font-size: 1.8rem;
            position: relative;
        }
        
        h3::after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
            width: 60px;
            height: 3px;
            background: linear-gradient(90deg, #ff69b4, #9370db);
            border-radius: 2px;
        }
        
        /* 错误消息 */
        .error-message {
            color: #ff6347;
            font-size: 14px;
            margin-top: 15px;
            padding: 10px;
            background: rgba(255, 99, 71, 0.1);
            border-radius: 10px;
            border-left: 4px solid #ff6347;
            animation: shake 0.5s ease;
        }
        
        @keyframes shake {
            0%, 100% { transform: translateX(0); }
            10%, 30%, 50%, 70%, 90% { transform: translateX(-5px); }
            20%, 40%, 60%, 80% { transform: translateX(5px); }
        }
        
        /* 响应式设计 */
        @media (max-width: 768px) {
            .login-form {
                padding: 30px 20px;
                margin: 20px;
                max-width: 100%;
            }
            
            h1 {
                font-size: 2rem;
                margin-bottom: 20px;
            }
            
            h3 {
                font-size: 1.5rem;
            }
        }
    </style>
</head>
<body>
    <h1>😻 每日吸猫 😻</h1>
    <div id="login-form" class="login-form">
        <h3>请登录</h3>
        <input type="text" id="username" placeholder="用户名">
        <input type="password" id="password" placeholder="密码">
        <button id="login-button">登录</button>
        <div id="error-message" class="error-message hidden"></div>
        <div style="margin-top: 20px; text-align: center;">
            <button id="register-button" style="background-color: #9370db; margin-top: 10px;">注册新账号</button>
        </div>
    </div>

    <script>
        // 登录功能
        const usernameInput = document.getElementById('username');
        const passwordInput = document.getElementById('password');
        const loginButton = document.getElementById('login-button');
        const errorMessage = document.getElementById('error-message');
        
        async function login() {
            const username = usernameInput.value;
            const password = passwordInput.value;
            
            if (!username || !password) {
                showError('请输入用户名和密码');
                return;
            }
            
            try {
                // 尝试向后端发送登录请求
                const response = await fetch('http://localhost:8080/api/user/login', {
                    method: 'POST',
                    headers: {
                        'Content-Type': 'application/json'
                    },
                    body: JSON.stringify({ username, password })
                });
                
                const data = await response.json();
                
                if (data.success) {
                    // 登录成功，存储用户信息并跳转到主页（包含导航栏和社区功能）
                    localStorage.setItem('currentUser', username);
                    window.location.href = 'cat.html';
                } else {
                    showError('用户名或密码错误！');
                }
            } catch (error) {
                console.error('登录失败:', error);
                showError('登录失败，请检查网络连接或联系管理员');
            }
        }
        
        // 跳转到注册页面
        function goToRegister() {
            window.location.href = 'register.html';
        }
        
        // 显示错误信息
        function showError(message) {
            errorMessage.textContent = message;
            errorMessage.classList.remove('hidden');
            setTimeout(() => {
                errorMessage.classList.add('hidden');
            }, 3000);
        }
        
        // 登录按钮事件
        loginButton.addEventListener('click', login);
        
        // 注册按钮事件
        document.getElementById('register-button').addEventListener('click', goToRegister);
        
        // 回车键登录
        usernameInput.addEventListener('keyup', (e) => {
            if (e.key === 'Enter') {
                login();
            }
        });
        
        passwordInput.addEventListener('keyup', (e) => {
            if (e.key === 'Enter') {
                login();
            }
        });
    </script>
</body>
</html>